import test from 'ava';
import { common } from '../index.js'
const { uuid, md5, sleep, datetime, humanSize,getHumanTime,isArray } = common;

test('uuid', t => {
  t.is(uuid().length, 36);
  t.is(uuid('v1').length, 36);
});


test('md5', t => {
  let str = md5('1');
  t.is(str, "c4ca4238a0b923820dcc509a6f75849b");
});

test('sleep', async t => {
  await sleep(1000);
  t.pass();
});

test('datetime', t => {
  let d = new Date(2024, 0, 1);
  let time = datetime(d);
  t.is(time, '2024-01-01 00:00:00');
});

test('humanSize', t => {
  let size = 1024000;
  let sizeStr = humanSize(size);
  t.is(sizeStr, '1000.00 KB');

  let size2 = 1000000000;
  let sizeStr2 = humanSize(size2);
  t.is(sizeStr2, '953.67 MB');
});

test('getHumanTime', t => {
  let seconds = 100;
  let time = getHumanTime(seconds); 
  t.is(time, '1m 40s');
  let seconds2 = 1000;
  let time2 = getHumanTime(seconds2);
  t.is(time2, '16m 40s');
});
test('isArray', t => {
  let a = '', b = [1];
  t.is(isArray(a), false);
  t.is(isArray(b), true);
});
